package com.xu.a2019;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

public class MyAdapter extends BaseListViewAdapter<BlogBean> {

    public MyAdapter(Context context, List<BlogBean> list) {
        super(context, list);
    }

    @Override
    protected int setContentView(int position) {
        return R.layout.item_data;
    }

    @Override
    public void convert(BaseViewHolder holder, final BlogBean o) {
        LinearLayout back = holder.findViewById(R.id.background);
        TextView tvw = holder.findViewById(R.id.tv_week);
        TextView tvd = holder.findViewById(R.id.tv_date);
        TextView et1 = holder.findViewById(R.id.tv_content_1);
        TextView et2 = holder.findViewById(R.id.tv_content_2);
        CheckBox checkBox = holder.findViewById(R.id.cb);
        checkBox.setChecked(false);
        tvw.setText(o.getWeek());
        tvd.setText(o.getDate());
        et1.setText(o.getContent());
        et2.setText(o.getContent2());
        switch (o.getFlag()) {
            case 0:
                back.setBackground(ContextCompat.getDrawable(mContext, R.drawable.shape_c6_all_yellow));
                break;
            case 1:
                back.setBackground(ContextCompat.getDrawable(mContext, R.drawable.shape_c6_all_white));
                break;
            case -1:
                back.setBackground(ContextCompat.getDrawable(mContext, R.drawable.shape_c6_all_gray));
                break;
            case 2:
                back.setBackground(null);
                et1.setBackground(null);
                et2.setBackground(null);
                et1.setFocusable(false);
                et2.setFocusable(false);
                tvw.setTextSize(14);
                tvd.setTextSize(14);
                et1.setTextSize(14);
                et2.setTextSize(14);
                break;
            case 4:
                checkBox.setChecked(true);
            default:
                break;
        }
        et1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                o.setContent(charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        et2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                o.setContent2(charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }
}
